package ms.unicorn;

import java.util.Collection;


public interface NotificationService {
	
	// predefined channel
	
	/**
	 * This channel is broadcasted by the {@link ms.unicorn.impl.ElementImpl#eNotify(org.eclipse.emf.common.notify.Notification) Element.eNotify(Notification notification)}
	 * The <b>event</b> equals to {@link org.eclipse.emf.common.notify.Notification#getEventType() notification.getEventType()}, subscription data is the <b>notification</b>.
	 * <p>
	 * @see org.eclipse.emf.common.notify.Notification#SET Notification.SET
	 * @see org.eclipse.emf.common.notify.Notification#UNSET Notification.UNSET
	 * @see org.eclipse.emf.common.notify.Notification#CREATE Notification.CREATE
	 * @see org.eclipse.emf.common.notify.Notification#ADD Notification.ADD
	 * @see org.eclipse.emf.common.notify.Notification#ADD_MANY Notification.ADD_MANY
	 * @see org.eclipse.emf.common.notify.Notification#REMOVE Notification.REMOVE
	 * @see org.eclipse.emf.common.notify.Notification#REMOVE_MANY Notification.REMOVE_MANY
	 **/
	public static final int CHANNEL_ELEMENT = 0x100;

	public static final int CHANNEL_EDITPART = 0x102;
	
	public static final int CHANNEL_OUTLINE = 0x103;
	
	public static final int CHANNEL_ELEMENT_CHANGE = 0x104;
	
	public static final int CUSTOM_CHANNEL = 0x104;
	
	public static final int OUTLINE_TEXT = 1;
	
	public static final int OUTLINE_IMAGE = 2;
	
	public static final int OUTLINE_CHILDREN = 3;
	
	// Subscription handling result
	public static final int SUBSCRIPTION_EXPIRED = 1;
	public static final int SUBSCRIPTION_NORMAL = 0;
	
	public interface Subscription<DataType, ResultType> {
		int getEvent();
		DataType getData();
		ResultType getResult();
		void setResult(ResultType result);
	}
	
	public interface Subscriber<DataType, ResultType> {
		Collection<Integer> getPreferChannels();
		int hanldeSubscription(Object sender, int channel, Subscription<DataType, ResultType> subscription);
	}
	
	Subscriber<?,?> registerSubscriber(Subscriber<?,?> subscriber);
	void unregisterSubscriber(Subscriber<?,?> subscriber);
	
	Object dispatch(Object sender, int channel, Subscription<?,?> subscription);
	<DataType, ResultType> ResultType dispatch(Object sender, int channel, int event, DataType data);
}
